//
//  LKStatusModel.swift
//  LKWeibo
//
//  Created by like on 16/8/13.
//  Copyright © 2016年 like. All rights reserved.
//

import UIKit

class LKStatusModel: NSObject {
    
    // MARK: - 模型属性
    /// 创建时间
    var created_at: String?
    /// 微博ID
    var id: Int64 = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    //用户信息的model
    var user: LKUserModel?
    
    //转发微博
    var retweeted_status:LKStatusModel?

    //配图
    var pic_urls:[LKPictureInfo]?
    
    // int	转发数
    var reposts_count: Int = 0
    // int	评论数
    var comments_count: Int = 0
    //int	表态数
    var attitudes_count: Int = 0
    
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    //重写系统的赋值方法，因为有user 这个模型， 系统自己不会帮我们转
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key == "user"{
            guard let v = value as? [String: AnyObject] else{
                return
            }
            // 手动给user赋值
            user = LKUserModel(dict: v)
            
        }else if key == "retweeted_status"{
            //判断不为nil  且 能转为字典
            guard let v = value as? [String: AnyObject] else{
                return
            }
            retweeted_status = LKStatusModel(dict: v)
            
        }else if key == "pic_urls" {
            //判断是否为nil  且能转为数组
            guard let v = value as? [[String: AnyObject]]else{
                return
            }
            
            //遍历数组，数组中的字典 转模型
            var tempArray: [LKPictureInfo] = [LKPictureInfo]()
            
            for val in v {
                
                let model = LKPictureInfo(dict: val)
                
                tempArray.append(model)
            }
            
            pic_urls = tempArray
            
        }else{
            super.setValue(value, forKey: key)
        }
   
    }
    
    
    //防止报错的方法
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
  
}
